from dendritetics_classes import *
from pylab import *

# generate a chromosome, randomly from the config file
chromo = Cchromosome()

# from this chromosomes first gene, make a dendritic tree
t1 = Ctree(chromo.genes[0])
# let the tree generate up to the first children
for i in range(2):
    t1.generate()
    t1.add_synapse_locations()

figure(1)
# plot the parameters that are functions of the distance to soma and their error lines
#   and the sampled values
# --- LENGTH ---
subplot(411)
l = array( t1.gene.list_form("length") ).transpose()
lu = array( t1.gene.list_form("length",error="upper") ).transpose()
ll = array( t1.gene.list_form("length",error="lower") ).transpose()
ls = array( t1.esampled_length ).transpose()
plot(l[0],l[1],'k',lu[0],lu[1],'r--',ll[0],ll[1],'r--',ls[0],ls[1],'bo')
ylabel('Length (um)')

# --- LS_DENSITY ---
subplot(412)
lsd = array( t1.gene.list_form("ls_density") ).transpose()
lsds = array( t1.esampled_ls_density ).transpose()
plot(lsd[0],lsd[1],'k',lsds[0],lsds[1],'bo')
ylabel('ls_density (syn/um)')


# --- ASYMMETRY ---
subplot(413)
a = array( t1.gene.list_form("asymmetry") ).transpose()
au = array( t1.gene.list_form("asymmetry",error="upper") ).transpose()
al = array( t1.gene.list_form("asymmetry",error="lower") ).transpose()
as = array( t1.esampled_asymmetry ).transpose()
plot(a[0],a[1],'k',au[0],au[1],'r--',al[0],al[1],'r--',as[0],as[1],'bo')
ylabel('Asymmetry (arb)')

# --- BRANCHING ANGLE ---
subplot(414)
ba = array( t1.gene.list_form("branching_angle") ).transpose()
bau = array( t1.gene.list_form("branching_angle",error="upper") ).transpose()
bal = array( t1.gene.list_form("branching_angle",error="lower") ).transpose()
bas = array( t1.esampled_branching_angle ).transpose()
# because the sampling process converts to radians, we must convert back to degrees here
bas[1] = bas[1] * 180/pi
plot(ba[0],ba[1],'k',bau[0],bau[1],'r--',bal[0],bal[1],'r--',bas[0],bas[1],'bo')
ylabel('Alpha (degrees)')
xlabel('Distance to Soma (um)')

show()

